<template>
  <!-- 账户明细 -->
  <el-dialog
    title="锁定用户"
    :visible.sync="show"
    width="500px"
    append-to-body
    :close-on-click-modal="false"
    @close="handleClose"
  >
    <el-form ref="formRef" :model="form" :rules="rules" label-width="80px" size="small">
      <el-form-item label="锁定类型" prop="banType">
        <YxhySelect :value.sync="form.banType" :columns="banColumns" />
      </el-form-item>
      <el-form-item label="锁定原因" prop="note">
        <el-input v-model="form.note" placeholder="请输入锁定原因" />
      </el-form-item>
      <el-form-item label="锁定时间" prop="exp_time">
        <YxhySelect :value.sync="form.exp_time" :columns="expTimeColumns" />
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="handleClose">关闭</el-button>
      <el-button type="primary" @click="handleSubmit">提交</el-button>
    </div>
  </el-dialog>
</template>

<script>

import { banUser } from '@/api/user/userData'
export default {
  name: 'CagingUser',
  props: {
    user_id: {
      type: [Number, String]
    }
  },
  data() {
    return {
      show: false,
      // 表单参数
      form: {
        user_id: undefined,
        banType: 1,
        note: undefined,
        exp_time: '' // 1=7天 2=永久
      },
      // 表单校验
      rules: {
        exp_time: [
          { required: true, message: '请选择锁定时间', trigger: ['blur', 'change'] }
        ]
      },
      banColumns: [
        { value: 1, label: '封号' }
      ],
      expTimeColumns: [
        { value: 1, label: '7天' },
        { value: 2, label: '永久' }
      ]

    }
  },
  methods: {
    handleOpen() {
      this.show = true
      this.form = {
        user_id: undefined,
        banType: 1,
        note: undefined,
        exp_time: '' // 1=7天 2=永久
      }
      this.form.user_id = this.$props.user_id
    },
    handleClose() {
      this.show = false
    },
    handleSubmit() {
      this.$refs['formRef'].validate((valid) => {
        if (valid) {
          banUser(this.form).then(res => {
            this.$modal.msgSuccess('操作成功')
            this.handleClose()
            this.$emit('refresh')
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
